package org.dpes.apriori;

import java.util.Iterator;

public class ZbiorStorage implements Iterable<Zbior>{
	
	int [][] storage;
	
	int index = 0;
	
	public ZbiorStorage(int n) {
		storage = new int[n][];
	}
	
	public void add(Zbior zbior) {
		storage[index] = new int[3];
		System.arraycopy(zbior.podajBity().getIndeks(), 0,storage[index], 0,3);
		index++;
	}

	@Override
	public Iterator<Zbior> iterator() {
		return new MojIT();
	}
	
	class MojIT implements Iterator<Zbior> {
		
		int counter = 0;

		@Override
		public boolean hasNext() {
			if (counter < index)
				return true;
			else
				return false;
		}

		@Override
		public Zbior next() {
			Zbior nowy = new Zbior();
			nowy.ustawBity(storage[counter]);
			counter++;
			return nowy;
		}

		@Override
		public void remove() {
		}
	}
	
	public int size() {
		return index;
	}
	
	
	@Override
	protected void finalize() throws Throwable {
		//System.out.println("zwalniam ZbiorStorage.");
	}

}
